
$(function(){
    get_wx_config()
})
var params = JSON.parse(window.localStorage.users)
console.log(params)
var id = params.id;
var name = params.name
var access_token = params.access_token
document.title = name
console.log(access_token)
var images = {
    localId: [],
    serverId: []
};
function take_a_photo(){
    wx.chooseImage({
        count: 1, // 默认9，这里每次只处理一张照片
        sizeType: ['original', 'compressed'],
        sourceType: ['camera'],
        success: function (res) {
            $('.photo_img img')[0].src = res.localIds;
            console.log(res.localIds)
                wx.uploadImage({
                    localId: res.localIds.toString(), // 需要上传的图片的本地ID，由chooseImage接口获得
                    success: function (res) {
                        images.serverId = res.serverId; // 返回图片的服务器端ID
                        if(!$('.photo_img img')[0].src == ''){
                            $('.photo_cp img')[0].src = './icon导出/重拍icon.png'
                        }
                    }
                });

        }
    });
}
$(document).on('click','.photo_cp',function () {
    take_a_photo()
})

function seveHandle(){
    document.cookie="patTow=;max-age=0;expires=Thu, 01 Jan 1970 00:00:00 GMT"
    if($('.photo_img img')[0].src == ''){
        layer.open({
            content: '图像不能为空'
            ,skin: 'msg'
            ,time: 2 //2秒后自动关闭
        });
    }else {
        var content = $('.text')[0].value
        layer.open({
            content: '恭喜你完成所有步骤'
            ,btn: ['确定提交', '再看一下']
            ,yes: function(index){
                Message(content)
                layer.close(index);
            }
        });
    }

}
function Message(content) {
    $.ajax({
        type: "POST",
        url: api('/stock-bill-record/create'),
        data: {
            access_token:access_token,
            id:id,
            img:images.serverId,
            content:content,
        },
        dataType: "json",
        success: function (res) {
            if(res.success){
                $.ajax({
                    type: "POST",
                    url: api('/stock-bill-record/create'),
                    data:{
                        access_token:access_token,
                        id:id,
                    },
                    dataType: "json",
                    success: function (res) {
                        console.log(res)
                        window.location.href = './complete.html?v='+ random +''
                    }
                })
            }else {
                console.log(res)
                layer.open({
                    content: res.message
                    ,skin: 'msg'
                    ,time: 2 //2秒后自动关闭
                });
            }
        }
    });
}
